//
//  LEOMainController.swift
//  SinaWeibo
//
//  Created by 李子海LEO on 4/6/16.
//  Copyright © 2016 李子海LEO. All rights reserved.
//

import UIKit

class LEOMainController: UITabBarController {

    

    
    
    override func viewDidLoad() {
        super.viewDidLoad()

      //  addChildViewController(navigationContrller2)//调用多少次,就添加多少个子控制器到 tabBarController 上

        addChildViewControllerTotabBarController()
        
        //自定义 tabBar --> KVC
        let tabBar=LEOTabBar()
        
        setValue(tabBar, forKey: "tabBar")
        
        print(tabBar.classForCoder)
        
        
    }
    
    //MARK:给UITabBarController 添加子控制器
    private func addChildViewControllerTotabBarController(){
        

        addNavigationController(LEOHomeController(), title: "首页", imageName: "tabbar_home")
        
        addNavigationController(LEOMessageController(), title: "消息", imageName: "tabbar_message_center")
        
        addNavigationController(LEODiscoveryController(), title: "发现", imageName: "tabbar_discover")
        
        addNavigationController(LEOProfileController(), title: "我", imageName: "tabbar_profile")

    }

    private func addNavigationController(controller:UIViewController, title:String, imageName:String){
        
        controller.title=title
        
        controller.tabBarItem.image=UIImage.init(named: imageName)
        
        //修改 tabBar 上的控件的颜色
        controller.tabBarItem.selectedImage=UIImage.init(named: imageName+"_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState:.Selected)

        let navigationController = UINavigationController(rootViewController:controller)

        addChildViewController(navigationController)
        
    }
    
}
